package com.demo.StudentController;

import com.demo.StudentService.SService;
import com.method.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 故我
 * Date: 2023-10-26
 * Time: 20:51
 */
@Controller
public class SController {
    //此时的spring中有两个student对象
//    @Resource(name="student1")//提供了各种方法获取到id的形式
//    private Student student;
//    public void Say(){
//        System.out.println(student.toString());
//    }
    @Autowired//此时获取不到id，请求其他的注解来救援
    @Qualifier("student2")
    private Student student;

    public void Say() {
        System.out.println(student.toString());
    }

    //前端传递信息给controller进行信息验证
    //1、使用属性注入获取bean对象
//    @Autowired
//    private SService sService;
//
//
//    //2、使用set注入的方式
//    private SService sService;
//
//    //    @Autowired //set注入还是不能解决final对象问题
////    public void setsService(SService sService) {
////        this.sService = sService;
////    }
//    //当类中只要一个构造方法时，可以省略autowired
////    @Autowired
////    public SController(SService sService) {
////        this.sService = sService;
////    }
//
//
//    @Resource
//    public void setsService(SService sService) {
//        this.sService = sService;
//    }
//
//    public void sayHi() {
//        sService.Say();
//    }
}
